﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkSplit
{
    public class A线前中后分离数据 : Object分离基类
    {
        public A线前中后分离数据(string name_SfcType) : base(name_SfcType)
        {
        }

        /// <summary>
        /// 获取A线分离数据
        /// </summary>
        /// <param name="a">A线数据集合</param>
        /// <param name="data">分离工段</param>
        /// <returns></returns>
        public static List<A线前中后分离数据> A线数据分离处理(List<A线数据> a, Dictionary<DataTable, string> data)
        {
            List<A线前中后分离数据> aPlus = new List<A线前中后分离数据>();
            List<string> Qian = new List<string>();
            List<string> Zhong = new List<string>();
            List<string> Hou = new List<string>();
            data.Where(x => x.Value == "Qian").ToList().ForEach(x =>
            {
                foreach (DataRow row in x.Key.Rows)
                {
                    Qian.Add(row["制程名称"].ToString());
                }
                
            }); 
            
            data.Where(x => x.Value == "Zhong").ToList().ForEach(x =>
            {
                foreach (DataRow row in x.Key.Rows)
                {
                    Zhong.Add(row["制程名称"].ToString());
                }

            });
            
            data.Where(x => x.Value == "Hou").ToList().ForEach(x =>
            {
                foreach (DataRow row in x.Key.Rows)
                {
                    Hou.Add(row["制程名称"].ToString());
                }

            });
            foreach (A线数据 A in a)
            {
                A线前中后分离数据 res = new A线前中后分离数据(A.data.TableName);
                foreach (DataRow row in A.data.Rows)
                {
                    foreach (KeyValuePair<DataTable, string> item in data)
                    {
                        //判断当前制程是否在数据库data变量中
                        if (Hou.Contains(row["制程名称"].ToString()))
                        {
                            res.Hou.Rows.Add(row.ItemArray);
                        }
                        else if (Qian.Contains(row["制程名称"].ToString()))
                        {
                            res.Qian.Rows.Add(row.ItemArray);
                        }
                        else if (Zhong.Contains(row["制程名称"].ToString()))
                        {
                            res.Zhong.Rows.Add(row.ItemArray);
                        }
                        break;
                    }
                }
                aPlus.Add(res);
            }
            return aPlus;
        }


    }
}
